package com.etl.plugin.datasource.admin;

import com.etl.plugin.datasource.pool.IBasePool;

import java.util.concurrent.ConcurrentHashMap;

//数据库连接池容器
public class DataBasePoolContainer {

    /**
     * 公共hashmap线程并发
     */
    private static ConcurrentHashMap<String, IBasePool> poolContioner = new ConcurrentHashMap<>();

    /**
     * 添加
     * @param key
     * @param value
     */
    public static void put(String key, IBasePool value){
        poolContioner.put(key,value);
    }

    /**
     * 获取
     * @param key
     * @param Class
     * @return
     * @param <T>
     */
    public static <T> T getConn(String key, Class<T> Class){
        IBasePool iBasePool = poolContioner.get(key);
        return (T) iBasePool.pull();
    }

    /**
     * 归还
     * @param key
     * @param obj
     */
    public static void backConn(String key, Object obj){
        poolContioner.get(key).back(obj);
    }

}
